export default {
  computed: {
    request() {
      return this.store.request
    }
  },
  methods: {
    filterParam(data) {
      return this.store.filterParam(data)
    },
    ajax(url = '', method = 'get', data = {}, headers = {}) {
      method = method.toLowerCase()
      data = method === 'post' ? { data } : { params: data }
      if (method === 'post' && !headers.hasOwnProperty('Content-Type')) {
        headers["Content-Type"] = "application/x-www-form-urlencoded"
      }
      return this.request(Object.assign(data, { url, headers, method }))
    },
    getNextNode(params, url = this.getNextNodeUrl) {
      return this.ajax(url, 'get', params)
    },
    delNode(data, url = this.delNodeUrl) {
      return this.ajax(url, 'post', data)
    },
    getNodeInfo(params, url = this.getNodeInfoUrl) {
      return this.ajax(url, 'get', params)
    },
    addNodeInfo(data, url = this.addNodeInfoUrl) {
      return this.ajax(url, 'post', this.filterParam(data))
    },
    updateNodeInfo(data, url = this.updateNodeInfoUrl) {
      return this.ajax(url, 'post', data)
    }
  }
}
